package com.ycy.upload;

import java.io.File;
import java.io.UnsupportedEncodingException;
import java.util.Arrays;
import java.util.ResourceBundle;

import javax.servlet.http.HttpServletRequest;

public class UploadUtil{

	private static ResourceBundle uploadRB = ResourceBundle.getBundle("upload");

	public static String getFilePath(){
		return uploadRB.getString("upload_file_path");
	}

	public static String[] getAllFileName(){
		String[] res = new File(getFilePath()).list();
		Arrays.sort(res);
		return res;
	}

	public static File getFile(String f){
		File res = new File(getFilePath() + "/" + f);
		return (res != null && res.isFile()) ? res : null;
	}

	public static String getParameter(String k, HttpServletRequest req){
		if (k == null || req == null || req.getParameter(k) == null) {
			return null;
		}
		String res = null;
		try {
			res = new String(req.getParameter(k).getBytes("ISO-8859-1"), "UTF-8");
		} catch (UnsupportedEncodingException e) {
			e.printStackTrace();
		}
		return res;
	}

	public static void main(String[] args){
		System.out.println(Arrays.toString(getAllFileName()));
	}

}
